/*
2021-7-13
https://ac.nowcoder.com/acm/contest/17942/E
*/
#include<iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    while(s.size()>1)
    {
        int sum=0;
        string temp;
        for(int i=0;i<s.size();i++)
        {
            sum+=s[i]-'0';
        }
        while(sum)
        {
            temp+=sum%10+'0';
            sum/=10;
        }
        s=temp;
    }
    cout<<s<<endl;
    return 0;
}
